﻿Public Class frmBrowser

    Dim BaseUri As String

    Public Shared Sub Init(Uri As String, Parent As Form)
        frmBrowser.BaseUri = Uri
        frmBrowser.Show(Parent)
    End Sub

    Private Sub frmBrowser_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        frmAbout.Shrink.BeginInvoke(Nothing, Nothing, Nothing)
    End Sub

    Private Sub frmBrowser_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Do Until frmAbout.Height = frmAbout.Width
            Application.DoEvents()
        Loop
        Browser.Navigate(BaseUri)
    End Sub

    Private Sub Browser_CanGoBackChanged(sender As Object, e As System.EventArgs) Handles Browser.CanGoBackChanged
        btnBack.Enabled = Browser.CanGoBack
    End Sub

    Private Sub Browser_CanGoForwardChanged(sender As Object, e As System.EventArgs) Handles Browser.CanGoForwardChanged
        btnForward.Enabled = Browser.CanGoForward
    End Sub

    Private Sub Browser_Navigating(sender As Object, e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles Browser.Navigating
        btnRefresh.Visible = False
        btnStop.Visible = True
    End Sub

    Private Sub Browser_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles Browser.DocumentCompleted
        txtURL.Text = Browser.Url.AbsoluteUri
        btnRefresh.Visible = True
        btnStop.Visible = False
    End Sub

    Private Sub btnBack_Click(sender As System.Object, e As System.EventArgs) Handles btnBack.Click
        If Browser.CanGoBack Then Browser.GoBack()
    End Sub

    Private Sub btnForward_Click(sender As System.Object, e As System.EventArgs) Handles btnForward.Click
        If Browser.CanGoForward Then Browser.GoForward()
    End Sub

    Private Sub btnRefresh_Click(sender As System.Object, e As System.EventArgs) Handles btnRefresh.Click
        Browser.Refresh()
    End Sub

    Private Sub btnStop_Click(sender As Object, e As System.EventArgs) Handles btnStop.Click
        Browser.Stop()
    End Sub

    Private Sub btnHome_Click(sender As System.Object, e As System.EventArgs) Handles btnHome.Click
        Browser.Navigate(BaseUri)
    End Sub

    Private Sub btnGoto_Click(sender As System.Object, e As System.EventArgs) Handles btnGoto.Click
        Browser.Navigate(txtURL.Text)
    End Sub

    Private Sub btnEscape_Click(sender As System.Object, e As System.EventArgs) Handles btnEscape.Click
        Me.Close()
    End Sub

    Private Sub txtURL_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtURL.KeyDown
        If e.Modifiers = 0 AndAlso e.KeyCode = Keys.Enter Then
            Browser.Navigate(txtURL.Text)
            e.Handled = True
        End If
    End Sub

End Class